package com.ntschy.bt.service.IBtHelp.impl;

import com.ntschy.bt.entity.dataobject.BtHelp.BtHelp;
import com.ntschy.bt.entity.dataobject.BtHelp.SysDept;
import com.ntschy.bt.entity.dto.BtHelpDTO.AssignDTO.BtHelpAssignAllocationDTO;
import com.ntschy.bt.entity.dto.BtHelpDTO.AssignDTO.BtHelpAssignPageDTO;
import com.ntschy.bt.entity.vo.BtHelp.Assign.BtHelpAssignDetailsVO;
import com.ntschy.bt.entity.vo.BtHelp.Assign.BtHelpAssignPageVo;
import com.ntschy.bt.mapper.BtHelpAssignMapper;
import com.ntschy.bt.service.IBtHelp.IBtHelpAssignService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;


/**
 * <p>
 * 供需超市 服务实现类
 * </p>
 *
 * @author cm
 * @since 2020-12-28
 */
@Service
public class BtHelpAssignServiceImpl implements IBtHelpAssignService {

    @Resource
    private BtHelpAssignMapper btHelpAssignMapper;


    // * ================================================基础增删改查BEGIN============================================= *

    /**
     * 分页查询
     * 当前查询条件：根据企业名称｜企业分类 | 求助类型 | 提交时间 | 是否为返回类型 |状态 时间倒序
     * @param btHelp 分页查询对象
     * @return 供需超市列表
     */
    @Override
    public List<BtHelp> pageHelpAssign(BtHelp btHelp) {

        List<BtHelp> page = btHelpAssignMapper.pageHelpAssign(btHelp);

        return page;
    }


    /**
     * 详情查询
     * 当前查询条件：根据ID
     * @param id 详情查询ID
     * @return 详情对象
     */
    @Override
    public BtHelp detailsHelpAssing(String id) {
        return btHelpAssignMapper.detailsHelpAssing(id);
    }



    /**
     * 分配部门数据查询
     *
     * @param
     * @return 分配部门数据查询对象
     */
    @Override
    public List<SysDept> selectdept() {
        return btHelpAssignMapper.selectdept();
    }



    /**
     * 分配部门
     *
     * @param  btHelp
     * @return 修改结果
     */
    @Override
    public int updatedistribution(BtHelp btHelp) {
        return btHelpAssignMapper.updatedistribution(btHelp);
    }


    // * ================================================基础增删改查BEGIN============================================= *


    /**
     * 查找相应的枚举类以供下拉选项
     * @param object 查找对象
     * @return 枚举列表
     */
    @SneakyThrows
    @Override
    public Map fingEnum(Object object)  {
        HashMap<String, Object> map = new HashMap<String,Object>();
        Field[] fields = object.getClass().getDeclaredFields();
        for (Field field : fields) {
            String name = field.getType().getName();
            Class<?> clazz = Class.forName(name);
            String attribute_name = field.getName();
            if(clazz.isEnum()){
                Method method = clazz.getMethod("values");
                Object invoke = method.invoke(clazz);
                Enum[] enums = (Enum[]) invoke;
                List list = Arrays.asList(enums);
                map.put(attribute_name,list);
                System.out.println(list);

            }else{
                continue;
            }

        }
        return map;
    }


}
